<template>
	<view class="">
		<view>
			<u--form errorType="toast" :model="form" ref="myForm" labelPosition="top" labelWidth="80">
				<u-form-item label="提现金额" prop="value" borderBottom>
					<u-input v-model="form.value" border="none" type="digit" placeholder="请输入提现金额">
						<text slot="prefix">￥</text>
					</u-input>
				</u-form-item>
				<view class="fsize-26 bg-white padding-30">
					<text class="line-gray">当前可提现金额为￥{{data.bonusBalance}},</text>
					<text class="line-yellow ml-10" @click="form.value = data.bonusBalance">全部提现</text>
				</view>
			</u--form>
		</view>
		<view class="pl-30 pr-30 mt-40">
			<u-button color="#e54d42" text="提现" @click="submit" size="large" shape="circle"/>
		</view>
		<u-toast ref="uToast" />
	</view>
</template>

<script>
	import { mapState, mapMutations } from 'vuex'
	export default {
		data() {
			return {
				form: {
					value: '',
				},
				data: {},
			}
		},
		computed: {
			...mapState(['userInfo'])
		},
		onLoad() {	
			this.getData()
		},
		methods: {
			...mapMutations(['setUserInfo']),
			getData(){
				this.$reqJsonPost('GetStockHolderDetails',{id: this.userInfo.userId}).then(res=>{
					this.data = res.data
				})
			},
			submit() {
				if(uni.$u.test.isEmpty(this.form.value)){
					this.$refs.uToast.show({
						message: '请输入提现金额'
					})
					return
				}
				if(this.form.value > this.data.bonusBalance) {
					this.$refs.uToast.show({
						message: '提现金额不能大于最大可提现金额'
					})
				} else {
					this.$reqJsonPost('StaffSettlementDoCreate', {value:this.form.value, id: this.userInfo.userId}).then(res => {
						this.$refs.uToast.show({
							message: res.msg,
							complete() {
								// that.setUserInfo({...that.userInfo,bonusBalance:that.form.nickName})
								uni.navigateBack()
							}
						})
					})
				}
			}
		},
	}
</script>

<style lang="scss" scoped>
</style>
